package lapsnake.main;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JPanel;

import owg.util.awt.StatefulJFrame;
import lapsnake.core.LapCore;
import lapsnake.settings.Settings;

public class LapSnake
{
    public static void main(String[] args)
    {
	new LapSnake();
    }

    public static LapSnake lapSnake;

    public static StatefulJFrame frame;
    public static JPanel tlp;

    public static Settings settings;

    public static String DIRECTORY;

    public LapSnake()
    {
	lapSnake = this;
	frame = new StatefulJFrame("Lap Snake");
	tlp = new JPanel(new BorderLayout());

	frame.add(tlp);
	tlp.setPreferredSize(new Dimension(640, 480));

	settings = Settings.open();
	if(settings.windowedBounds == null)
	{ 
	    frame.pack();
	    frame.setLocationRelativeTo(null);
	}
	else
	{
	    frame.setBounds(settings.windowedBounds);
	}
	if(settings.isFullscreen)
	    frame.setExtendedState(Frame.MAXIMIZED_BOTH);

	new LapCore(tlp, BorderLayout.CENTER);

	frame.addWindowListener(new WindowAdapter()
	{
	    @Override
	    public void windowClosing(WindowEvent e)
	    {
		//TODO
		settings.save();
		System.exit(0);
	    }
	});

	frame.setVisible(true);
    }
}
